package com.aube.rvi;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.view.ContextThemeWrapper;

import com.aube.rvi.module.DLPluginPackage;

/**
 * Created by huyaonan on 16/10/26.
 */
public class ProxyContext extends ContextThemeWrapper {

    private DLPluginPackage mPlugin;

    public ProxyContext(Context baseContext, DLPluginPackage pluginPackage) {
        attachBaseContext(baseContext);
        mPlugin = pluginPackage;
    }

    @Override
    public Resources getResources() {
        return mPlugin.resources == null ? super.getResources() : mPlugin.resources;
    }

    @Override
    public ClassLoader getClassLoader() {
        return mPlugin.classLoader == null ? super.getClassLoader() : mPlugin.classLoader;
    }

    @Override
    public AssetManager getAssets() {
        return mPlugin.assetManager == null ? super.getAssets() : mPlugin.assetManager;
    }

    @Override
    public Resources.Theme getTheme() {
        return mPlugin == null ? super.getTheme() : mPlugin.resources.newTheme();
    }

}
